package server;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;

//Logger library
import org.apache.log4j.Logger;

public class ServerPresentazione{
	
	private static Logger logger = Logger.getLogger(ServerPresentazione.class);
	private static final long serialVersionUID = 1;
	
	
	public String IPServer= "127.0.0.1";
	public String portServer="12345";
	String registryURL;
	static Ui_server ui;
		
	
	public void setIp(String ip){
		IPServer= ip;
	}
	
	public void setPort(String port){
		portServer =port;	
	}


	public String bind() throws RemoteException, MalformedURLException{
		
		ServerImplement server_ref = new ServerImplement();
		
		registryURL="//"+IPServer+":"+portServer+"/RMIPresentazione";
		Naming.rebind(registryURL, server_ref);
		 System.out.println("Server ready");
		return registryURL;
		
	}
	public void unbind() throws RemoteException, MalformedURLException, NotBoundException {
		Naming.unbind(registryURL);
	}
	
		
	
	public static void main(String[] args) {
		logger.info("Server Presentazione Avviato");
		if (System.getSecurityManager() == null)
		  System.setSecurityManager(new RMISecurityManager());
	       		
			ui = new Ui_server();
			ui.setVisible(true);
			logger.info("Avvio interfaccia Grafica Server");
			ui.initComponents();
			
			}
		
	}




	
